package com.xiaohong.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaohong.user.dao.ChatUsernameListMapper;
import com.xiaohong.user.pojo.UsernameList;
import com.xiaohong.user.service.ChatUsernameListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChatUsernameListServiceImpl implements ChatUsernameListService {

    @Autowired
    private ChatUsernameListMapper chatUsernameListMapper;


    /**
     * 条件+分页查询ChatUsernameList
     * @param usernameList 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<UsernameList> findPage(UsernameList usernameList, int page, int size){
        // 构建查询条件
        QueryWrapper<UsernameList> queryWrapper = new QueryWrapper<UsernameList>(usernameList);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return chatUsernameListMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询ChatUsernameList
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<UsernameList> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return chatUsernameListMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法ChatUsernameList
     * @param usernameList
     * @return
     */
    @Override
    public List<UsernameList> findList(UsernameList usernameList){
        // 构建查询条件
        QueryWrapper<UsernameList> queryWrapper = new QueryWrapper<UsernameList>(usernameList);
        // 查询数据
        return chatUsernameListMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除ChatUsernameList
     * @param id
     */
    @Override
    public void delete(Long id){
        chatUsernameListMapper.deleteById(id);
    }

    /**
     * 根据ID修改ChatUsernameList
     * @param usernameList
     */
    @Override
    public void update(UsernameList usernameList){
        // 初始化一些不可修改数据
        usernameList.setGmtModified(null);
        usernameList.setGmtCreate(null);
        usernameList.setVersion(null);
        usernameList.setDeleted(null);
        chatUsernameListMapper.updateById(usernameList);
    }

    /**
     * 增加ChatUsernameList
     * @param usernameList
     */
    @Override
    public void add(UsernameList usernameList){
        chatUsernameListMapper.insert(usernameList);
    }

    /**
     * 根据ID查询ChatUsernameList
     * @param id
     * @return
     */
    @Override
    public UsernameList findById(Long id){
        return  chatUsernameListMapper.selectById(id);
    }

    /**
     * 查询全部ChatUsernameList数据
     * @return
     */
    @Override
    public List<UsernameList> findAll() {
        return chatUsernameListMapper.selectList(null);
    }
}
